class Solution {
public:
    bool isPalindrome(string str) {
        str.erase(remove_if(str.begin(), str.end(), [](char c) {
            return !('A' <= c && 'Z' >= c || 'a' <= c && 'z' >= c || '0' <= c && '9' >= c); 
        }), str.end());
        transform(str.begin(), str.end(), str.begin(), [](char c) {
            return tolower(c); 
        });

        for (int i = 0, j = str.length() - 1; i < j; i++, j--)
            if (str[i] != str[j])
                return false;

        return true;
    }
};